package com.rika.controller;

import com.rika.pojo.Category;
import com.rika.pojo.Vender;
import com.rika.response.QueryResult;
import com.rika.response.Result;
import com.rika.service.VenderService;
import com.rika.util.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class VenderController {
    @Resource
    private VenderService venderService;
    @RequestMapping("getAllVender")
    public QueryResult selectAllVender(Integer currentPage,Integer pageSize){
        Page page=new Page(currentPage,pageSize);
        Map<String,Object> params=new HashMap<>();
        params.put("first",page.getFirst());
        params.put("max",page.getMax());
        List<Vender> list=venderService.selectAllVender(params);
        int total=venderService.countAll();
        return QueryResult.ok(total,list);
    }
    @RequestMapping("addVender")
    public Result insertVender(Vender vender){
        Result result=new Result();
        venderService.insertVender(vender);
        result.setMsg("新增成功");
        result.setCode(200);
        return result;
    }
    @RequestMapping("deleteVender")
    public Result deleteVender(String venderCode){
        Result result=new Result();
        venderService.deleteVender(venderCode);
        result.setMsg("删除成功");
        result.setCode(200);
        return result;
    }
    @RequestMapping("selectByVenderCode")
    public Result selectByVenderCode(String venderCode){
        Result result=new Result();
        Vender list=venderService.selectByVenderCode(venderCode);
        result.setCode(200);
        result.setData(list);
        return result;
    }
    @RequestMapping("updateVender")
    public Result updateVender(Vender vender){
        Result result=new Result();
        venderService.updateVender(vender);
        result.setMsg("修改成功");
        result.setCode(200);
        return result;
    }
    @RequestMapping("selectAllVenderForPo")
    public Result selectAllVenderForPo(){
        Result result=new Result();
        List<Vender> list=venderService.selectAllVenderForPo();
        result.setCode(200);
        result.setData(list);
        return result;
    }
    @RequestMapping("selectVenderByName")
    public Result selectVenderByName(String name){
        Result result=new Result();
        List<Vender> list=venderService.selectVenderByName(name);
        result.setCode(200);
        result.setData(list);
        return result;
    }
}
